home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / cbasebal.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  10KB  |  366 lines

  1. /***************************************************************************
  2.  
  3.   Capcom Baseball
  4.  
  5.  
  6.   Somewhat similar to the "Mitchell hardware", but different enough to
  7.   deserve its own driver.
  8.  
  9. TODO:
  10. - understand what bit 6 of input port 0x12 is
  11. - unknown bit 5 of bankswitch register
  12.  
  13. ***************************************************************************/
  14.  
  15. #include "driver.h"
  16. #include "vidhrdw/generic.h"
  17. #include "machine/eeprom.h"
  18.  
  19.  
  20. /* in machine/kabuki.c */
  21. void pang_decode(void);
  22.  
  23.  
  24. int cbasebal_vh_start(void);
  25. void cbasebal_vh_stop(void);
  26. WRITE_HANDLER( cbasebal_textram_w );
  27. READ_HANDLER( cbasebal_textram_r );
  28. WRITE_HANDLER( cbasebal_scrollram_w );
  29. READ_HANDLER( cbasebal_scrollram_r );
  30. WRITE_HANDLER( cbasebal_gfxctrl_w );
  31. WRITE_HANDLER( cbasebal_scrollx_w );
  32. WRITE_HANDLER( cbasebal_scrolly_w );
  33. void cbasebal_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  34.  
  35.  
  36. static int rambank;
  37.  
  38. static WRITE_HANDLER( cbasebal_bankswitch_w )
  39. {
  40.     int bankaddress;
  41.     unsigned char *RAM = memory_region(REGION_CPU1);
  42.  
  43.     /* bits 0-4 select ROM bank */
  44. //logerror("%04x: bankswitch %02x\n",cpu_get_pc(),data);
  45.     bankaddress = 0x10000 + (data & 0x1f) * 0x4000;
  46.     cpu_setbank(1,&RAM[bankaddress]);
  47.  
  48.     /* bit 5 used but unknown */
  49.  
  50.     /* bits 6-7 select RAM bank */
  51.     rambank = (data & 0xc0) >> 6;
  52. }
  53.  
  54.  
  55. static READ_HANDLER( bankedram_r )
  56. {
  57.     if (rambank == 2)
  58.         return cbasebal_textram_r(offset);    /* VRAM */
  59.     else if (rambank == 1)
  60.     {
  61.         if (offset < 0x800)
  62.             return paletteram_r(offset);
  63.         else return 0;
  64.     }
  65.     else
  66.     {
  67.         return cbasebal_scrollram_r(offset);    /* SCROLL */
  68.     }
  69. }
  70.  
  71. static WRITE_HANDLER( bankedram_w )
  72. {
  73.     if (rambank == 2)
  74.         cbasebal_textram_w(offset,data);
  75.     else if (rambank == 1)
  76.     {
  77.         if (offset < 0x800)
  78.             paletteram_xxxxBBBBRRRRGGGG_w(offset,data);
  79.     }
  80.     else
  81.         cbasebal_scrollram_w(offset,data);
  82. }
  83.  
  84. static WRITE_HANDLER( cbasebal_coinctrl_w )
  85. {
  86.     coin_lockout_w(0,~data & 0x04);
  87.     coin_lockout_w(1,~data & 0x08);
  88.     coin_counter_w(0,data & 0x01);
  89.     coin_counter_w(1,data & 0x02);
  90. }
  91.  
  92.  
  93.  
  94. /***************************************************************************
  95.  
  96.   EEPROM
  97.  
  98. ***************************************************************************/
  99.  
  100. static struct EEPROM_interface eeprom_interface =
  101. {
  102.     6,        /* address bits */
  103.     16,        /* data bits */
  104.     "0110",    /*  read command */
  105.     "0101",    /* write command */
  106.     "0111"    /* erase command */
  107. };
  108.  
  109.  
  110. static void nvram_handler(void *file,int read_or_write)
  111. {
  112.     if (read_or_write)
  113.         EEPROM_save(file);
  114.     else
  115.     {
  116.         EEPROM_init(&eeprom_interface);
  117.  
  118.         if (file)
  119.             EEPROM_load(file);
  120.     }
  121. }
  122.  
  123. static READ_HANDLER( eeprom_r )
  124. {
  125.     int bit;
  126.  
  127.     bit = EEPROM_read_bit() << 7;
  128.  
  129.     return (input_port_2_r(0) & 0x7f) | bit;
  130. }
  131.  
  132. static WRITE_HANDLER( eeprom_cs_w )
  133. {
  134.     EEPROM_set_cs_line(data ? CLEAR_LINE : ASSERT_LINE);
  135. }
  136.  
  137. static WRITE_HANDLER( eeprom_clock_w )
  138. {
  139.     EEPROM_set_clock_line(data ? CLEAR_LINE : ASSERT_LINE);
  140. }
  141.  
  142. static WRITE_HANDLER( eeprom_serial_w )
  143. {
  144.     EEPROM_write_bit(data);
  145. }
  146.  
  147.  
  148.  
  149. static struct MemoryReadAddress cbasebal_readmem[] =
  150. {
  151.     { 0x0000, 0x7fff, MRA_ROM },
  152.     { 0x8000, 0xbfff, MRA_BANK1 },
  153.     { 0xc000, 0xcfff, bankedram_r },
  154.     { 0xe000, 0xffff, MRA_RAM },
  155.     { -1 }  /* end of table */
  156. };
  157.  
  158. static struct MemoryWriteAddress cbasebal_writemem[] =
  159. {
  160.     { 0x0000, 0xbfff, MWA_ROM },
  161.     { 0xc000, 0xcfff, bankedram_w, &paletteram },    /* palette + vram + scrollram */
  162.     { 0xe000, 0xfdff, MWA_RAM },            /* work RAM */
  163.     { 0xfe00, 0xffff, MWA_RAM, &spriteram, &spriteram_size },
  164.     { -1 }  /* end of table */
  165. };
  166.  
  167. static struct IOReadPort cbasebal_readport[] =
  168. {
  169.     { 0x10, 0x10, input_port_0_r },
  170.     { 0x11, 0x11, input_port_1_r },
  171.     { 0x12, 0x12, eeprom_r },
  172.     { -1 }  /* end of table */
  173. };
  174.  
  175. static struct IOWritePort cbasebal_writeport[] =
  176. {
  177.     { 0x00, 0x00, cbasebal_bankswitch_w },
  178.     { 0x01, 0x01, eeprom_cs_w },
  179.     { 0x02, 0x02, eeprom_clock_w },
  180.     { 0x03, 0x03, eeprom_serial_w },
  181.     { 0x05, 0x05, OKIM6295_data_0_w },
  182.     { 0x06, 0x06, YM2413_register_port_0_w },
  183.     { 0x07, 0x07, YM2413_data_port_0_w },
  184.     { 0x08, 0x09, cbasebal_scrollx_w },
  185.     { 0x0a, 0x0b, cbasebal_scrolly_w },
  186.     { 0x13, 0x13, cbasebal_gfxctrl_w },
  187.     { 0x14, 0x14, cbasebal_coinctrl_w },
  188.     { -1 }  /* end of table */
  189. };
  190.  
  191.  
  192. INPUT_PORTS_START( cbasebal )
  193.     PORT_START
  194.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNKNOWN )
  195.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON3 )
  196.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON2 )
  197.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON1 )
  198.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY )
  199.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY )
  200.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY )
  201.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY )
  202.  
  203.     PORT_START      /* IN2 */
  204.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNKNOWN )
  205.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER2 )
  206.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
  207.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
  208.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER2 )
  209.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER2 )
  210.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER2 )
  211.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER2 )
  212.  
  213.     PORT_START      /* IN0 */
  214.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
  215.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
  216.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN3 )
  217.     PORT_SERVICE( 0x08, IP_ACTIVE_LOW )
  218.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START2 )
  219.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 )
  220.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_VBLANK )        /* ? */
  221.     PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN )    /* EEPROM data */
  222. INPUT_PORTS_END
  223.  
  224.  
  225.  
  226.  
  227. static struct GfxLayout cbasebal_textlayout =
  228. {
  229.     8,8,    /* 8*8 characters */
  230.     4096,    /* 4096 characters */
  231.     2,        /* 2 bits per pixel */
  232.     { 0, 4 },
  233.     { 8+3, 8+2, 8+1, 8+0, 3, 2, 1, 0 },
  234.     { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 },
  235.     16*8    /* every char takes 16 consecutive bytes */
  236. };
  237.  
  238. static struct GfxLayout cbasebal_tilelayout =
  239. {
  240.     16,16,    /* 16*16 tiles */
  241.     4096,    /* 4096 tiles */
  242.     4,        /* 4 bits per pixel */
  243.     { 4096*64*8+4, 4096*64*8+0,4, 0 },
  244.     { 0, 1, 2, 3, 8+0, 8+1, 8+2, 8+3,
  245.             16*16+0, 16*16+1, 16*16+2, 16*16+3, 16*16+8+0, 16*16+8+1, 16*16+8+2, 16*16+8+3 },
  246.     { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16,
  247.             8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16 },
  248.     64*8    /* every tile takes 64 consecutive bytes */
  249. };
  250.  
  251. static struct GfxLayout cbasebal_spritelayout =
  252. {
  253.     16,16,  /* 16*16 sprites */
  254.     4096,   /* 2048 sprites */
  255.     4,      /* 4 bits per pixel */
  256.     { 4096*64*8+4, 4096*64*8+0, 4, 0 },
  257.     { 0, 1, 2, 3, 8+0, 8+1, 8+2, 8+3,
  258.             32*8+0, 32*8+1, 32*8+2, 32*8+3, 33*8+0, 33*8+1, 33*8+2, 33*8+3 },
  259.     { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16,
  260.             8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16 },
  261.     64*8    /* every sprite takes 64 consecutive bytes */
  262. };
  263.  
  264. static struct GfxDecodeInfo cbasebal_gfxdecodeinfo[] =
  265. {
  266.     { REGION_GFX1, 0, &cbasebal_textlayout,   256,  8 }, /* colors 256- 287 */
  267.     { REGION_GFX2, 0, &cbasebal_tilelayout,   768, 16 }, /* colors 768-1023 */
  268.     { REGION_GFX3, 0, &cbasebal_spritelayout, 512,  8 }, /* colors 512- 639 */
  269.     { -1 } /* end of array */
  270. };
  271.  
  272.  
  273.  
  274. static struct YM2413interface ym2413_interface=
  275. {
  276.     1,    /* 1 chip */
  277.     8000000,    /* 8MHz ??? (hand tuned) */
  278.     { 50 },    /* Volume */
  279. };
  280.  
  281. static struct OKIM6295interface okim6295_interface =
  282. {
  283.     1,            /* 1 chip */
  284.     { 8000 },    /* 8000Hz ??? */
  285.     { REGION_SOUND1 },    /* memory region */
  286.     { 50 }
  287. };
  288.  
  289.  
  290.  
  291. static struct MachineDriver machine_driver_cbasebal =
  292. {
  293.     {
  294.         {
  295.             CPU_Z80,
  296.             6000000,    /* ??? */
  297.             cbasebal_readmem,cbasebal_writemem,cbasebal_readport,cbasebal_writeport,
  298.             interrupt,1    /* ??? */
  299.         },
  300.     },
  301.     60, DEFAULT_REAL_60HZ_VBLANK_DURATION,    /* frames per second, vblank duration */
  302.     1,
  303.     0,
  304.  
  305.     64*8, 32*8, { 8*8, (64-8)*8-1, 2*8, 30*8-1 },
  306.     cbasebal_gfxdecodeinfo,
  307.     1024, 1024,
  308.     0,
  309.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE | VIDEO_UPDATE_BEFORE_VBLANK,
  310.     0,
  311.     cbasebal_vh_start,
  312.     cbasebal_vh_stop,
  313.     cbasebal_vh_screenrefresh,
  314.     0,0,0,0,
  315.     {
  316.         {
  317.             SOUND_OKIM6295,
  318.             &okim6295_interface
  319.         },
  320.         {
  321.             SOUND_YM2413,
  322.             &ym2413_interface
  323.         },
  324.     },
  325.  
  326.     nvram_handler
  327. };
  328.  
  329.  
  330.  
  331. ROM_START( cbasebal )
  332.     ROM_REGION( 2*0x90000, REGION_CPU1 )    /* 576k for code + 576k for decrypted opcodes */
  333.     ROM_LOAD( "cbj10.11j",    0x00000, 0x08000, 0xbbff0acc )
  334.     ROM_LOAD( "cbj07.16f",    0x10000, 0x20000, 0x8111d13f )
  335.     ROM_LOAD( "cbj06.14f",    0x30000, 0x20000, 0x9aaa0e37 )
  336.     ROM_LOAD( "cbj05.13f",    0x50000, 0x20000, 0xd0089f37 )
  337.     /* 0x70000-0x8ffff empty (space for 04) */
  338.  
  339.     ROM_REGION( 0x10000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  340.     ROM_LOAD( "cbj13.16m",    0x00000, 0x10000, 0x2359fa0a )    /* text */
  341.  
  342.     ROM_REGION( 0x80000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  343.     ROM_LOAD( "cbj02.1f",     0x00000, 0x20000, 0xd6740535 )    /* tiles */
  344.     ROM_LOAD( "cbj03.2f",     0x20000, 0x20000, 0x88098dcd )
  345.     ROM_LOAD( "cbj08.1j",     0x40000, 0x20000, 0x5f3344bf )
  346.     ROM_LOAD( "cbj09.2j",     0x60000, 0x20000, 0xaafffdae )
  347.  
  348.     ROM_REGION( 0x80000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  349.     ROM_LOAD( "cbj11.1m",     0x00000, 0x20000, 0xbdc1507d )    /* sprites */
  350.     ROM_LOAD( "cbj12.2m",     0x20000, 0x20000, 0x973f3efe )
  351.     ROM_LOAD( "cbj14.1n",     0x40000, 0x20000, 0x765dabaa )
  352.     ROM_LOAD( "cbj15.2n",     0x60000, 0x20000, 0x74756de5 )
  353.  
  354.     ROM_REGION( 0x80000, REGION_SOUND1 )    /* OKIM */
  355.     ROM_LOAD( "cbj01.1e",     0x00000, 0x20000, 0x1d8968bd )
  356. ROM_END
  357.  
  358.  
  359. void init_cbasebal(void)
  360. {
  361.     pang_decode();
  362. }
  363.  
  364.  
  365. GAME( 1989, cbasebal, 0, cbasebal, cbasebal, cbasebal, ROT0, "Capcom", "Capcom Baseball (Japan)" )
  366.